﻿using Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class frmLogin : Form
    {
        public static string namhoc="";
        public static string hocki="";
        public frmLogin()
        {
            InitializeComponent();
        }
        TaiKhoan tk = null;
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (namhoc == "" || hocki == "")
            {
                MessageBox.Show("chọn năm học và học kì");
            }
            else
            {
                tk = QLiTaiKhoan.Instance.Find(c => (c as TaiKhoan).Username == txtUserName.Text.Trim() &&
                    (c as TaiKhoan).Password == txtPass.Text) as TaiKhoan;
                if (tk != null)
                {
                    frmNguoiDung.User = tk;
                    ProxyQuanLi.Instance.Login(new frmMain(), new frmNguoiDung(), tk);
                }
                else
                    MessageBox.Show("Đăng nhập không thành công");
            }
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            cbhk.SelectedIndex = 0;
            cbnamhoc.SelectedIndex = 0;
        }

        private void cbnamhoc_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbnamhoc.SelectedIndex > 0)
                namhoc = cbnamhoc.Text;
        }

        private void cbhk_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbhk.SelectedIndex > 0)
                hocki = cbhk.Text;
                
        }
    }
}
